require 'UnicodeEx\WinEx.rb'

# Calls the Unicode (wide) versions of the Windows API's file functions.
#
# It's a subclass of the standard +FileTest+ class that only overrides the
# methods when it's run on a Windows system. Otherwise it functions as
# a normal +FileTest+ class.
# File methods not re-implemented will behave as normal - trying to call
# the ASCII Windows API.
module FileTestW #< FileTest
	
	# Override the methods only on PC systems.
	if WinEx::IS_PC
	
	# (!) Why do the methods come out at private? - We have to manually call FileTest::
	#     for the methods we've not implemeted yet?
	include FileTest
	#extend FileTest
	
	public :blockdev?,
			:chardev?,
			:directory?,
			:executable?,
			:executable_real?,
			:exist?,
			:exists?,
			:file?,
			:grpowned?,
			#:identical?,
			:owned?,
			:pipe?,
			:readable?,
			:readable_real?,
			:setgid?,
			:setuid?,
			:size,
			:size?,
			:socket?,
			:sticky?,
			:symlink?,
			:writable?,
			:writable_real?,
			:zero?
	
	# * +file_name+ --- UTF-8 +String+
	def directory?(file_name)
		file_name = WinEx::FileSystem::normalize_w(file_name)
		file_data = WinEx::FileSystem.get_file_data(file_name)
		return (file_data.file_attributes & WinEx::FILE_ATTRIBUTE_DIRECTORY == WinEx::FILE_ATTRIBUTE_DIRECTORY)
		# (!) Verify
	end
	
	# * +file_name+ --- UTF-8 +String+
	def exist?(file_name)
		file_name = WinEx::FileSystem::normalize_w(file_name)
		return !WinEx::FileSystem.get_file_data(file_name).nil?
	end
	alias :exists? :exist?
	
	# * +file_name+ --- UTF-8 +String+
	def size(file_name)
		# (?) Raise error if file not found?
		file_name = WinEx::FileSystem::normalize_w(file_name)
		return WinEx::FileSystem.get_file_data(file_name).file_size
	end
	
	# * +file_name+ --- UTF-8 +String+
	def size?(file_name)
		file_name = WinEx::FileSystem::normalize_w(file_name)
		attribs = WinEx::FileSystem.get_file_data(file_name)
		return nil if attribs.nil?
		return nil if attribs.file_size == 0
		return attribs.file_size
	end
	
	# * +file_name+ --- UTF-8 +String+
	def zero?(file_name)
		file_name = WinEx::FileSystem::normalize_w(file_name)
		attribs = WinEx::FileSystem.get_file_data(file_name)
		return false if attribs.nil?
		return true if attribs.file_size == 0
		return false
	end
	
	# Make the instance methods availible as class methods
	extend self
	
	end # if WinEx::IS_PC
	
end # module FileTestW